var fs = require("fs");
var cacheMap = {};
exports.cacheMapAction = function(req, res) {
    fs.readFile("cacheMap.js", function(error, data) {
            cacheMap = JSON.parse(data.toString());
            var cacheMapPool = {};
            var num = 0;
            function parseCache(count, path, md5) {
                    return function() {
                        if (path.indexOf("common/") > -1 || path.indexOf("component/") > -1) {
                            cacheMapPool[path] = false;
                            num++;
                        } else {
                            paths = path.split("/");
                            var localCacheMapMd5 = cacheMap;
                            for (var index = 0; index < paths.length; index++) {
                                if(typeof localCacheMapMd5[paths[index]] == "undefined") {
                                    localCacheMapMd5 = "";
                                    break;
                                }
                                localCacheMapMd5 = localCacheMapMd5[paths[index]];
                            }
                            if (md5 == localCacheMapMd5) {
                                cacheMapPool[path] = true;
                            } else {
                                cacheMapPool[path] = false;
                            }
                            num++;
                        }
                        if(num == count) {
                            res.json(cacheMapPool);
                        }
                    }
            }
            if(isUseGlobalCache) {
                var urls = req.param("url");
                urls = urls.split(",");
                for(var index = 0; index < urls.length; index++) {
                    var paths = urls[index].split(";");
                    var check = parseCache(urls.length, paths[0], paths[1]);
                    check();
                }
            } else {
                res.end("false");
            }
    });
}